package com.it.boot.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;

// @Configuration
public class DataSourceBeanConfig {
    // todo
    @Bean(name = "datasource1")
    @Profile("test")
    public DataSource testDataSource(Environment env) {

        return null;
    }

    @Bean(name = "datasource1")
    @Profile("prod") // @Profile({"test","!prod"})
    public DataSource prodDataSource(Environment env) {
        return null;
    }

    @Bean
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource dataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "readDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.read")
    public DataSource readDataSource() {
        return DataSourceBuilder.create().build();
    }
}
